
Partial Class DashboardControls_BatchUploadPortlet
    Inherits System.Web.UI.UserControl
    Implements IDashBoard

    Dim titleLabelString As String = ""
    Dim pageSizeValue As Integer = 0

    Public Property SortDirection() As System.Web.UI.WebControls.SortDirection Implements IDashBoard.SortDirection
        Get
            If ViewState("SortDirection") Is Nothing Then
                Return WebControls.SortDirection.Ascending
            Else
                Return ViewState("SortDirection")
            End If
        End Get
        Set(ByVal value As System.Web.UI.WebControls.SortDirection)
            ViewState("SortDirection") = value
        End Set
    End Property

    Public Property PageNumber() As Integer Implements IDashBoard.PageNumber
        Get
            Return Me.AlertsGridView.PageIndex
        End Get
        Set(ByVal value As Integer)
            Me.AlertsGridView.PageIndex = value
        End Set
    End Property

    Public Property PageSize() As Integer Implements IDashBoard.PageSize
        Get
            If Not IsNothing(Me.AlertsGridView) Then
                If Me.AlertsGridView.AllowPaging = False Then
                    Return -1
                Else
                    Return Me.AlertsGridView.PageSize
                End If

            Else
                Return pageSizeValue
            End If
        End Get
        Set(ByVal value As Integer)
            If Not IsNothing(Me.AlertsGridView) Then
                If value = -1 Then
                    Me.AlertsGridView.AllowPaging = False
                Else
                    Me.AlertsGridView.AllowPaging = True
                    Me.AlertsGridView.PageSize = value
                End If
                Me.NumberOfRowsDropDownList.SelectedValue = value.ToString()
            End If
            pageSizeValue = value
        End Set
    End Property
    Public Property SortField() As String Implements IDashBoard.SortField
        Get
            If ViewState("SortField") Is Nothing Then
                Return ""
            Else
                Return ViewState("SortField")
            End If
        End Get
        Set(ByVal value As String)
            ViewState("SortField") = value
        End Set
    End Property
    Public Property Title() As String Implements IDashBoard.Title
        Get
            If Me.TitleLabel IsNot Nothing Then
                Return TitleLabel.Text
            Else
                Return titleLabelString
            End If
        End Get
        Set(ByVal value As String)
            If TitleLabel IsNot Nothing Then
                TitleLabel.Text = value
            End If
            titleLabelString = value
        End Set
    End Property

    Protected Sub Page_Init(ByVal sender As Object, _
                        ByVal e As System.EventArgs) _
                        Handles Me.Init

        AddHandler NumberOfRowsDropDownList.SelectedIndexChanged, AddressOf NumberOfRowsDropDownList_SelectedIndexChanged

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, _
                        ByVal e As System.EventArgs) _
                        Handles Me.Load

        If Me.IsPostBack Then
            AddHandler NumberOfRowsDropDownList.SelectedIndexChanged, AddressOf NumberOfRowsDropDownList_SelectedIndexChanged
        End If

        If Not String.IsNullOrEmpty(titleLabelString) Then
            Me.TitleLabel.Text = titleLabelString
        End If

        If pageSizeValue > 0 Then
            Me.PageSize = pageSizeValue
        End If


        If Not Me.IsPostBack Then
            GridViewSettingController.SetGridViewValues(Me, 5, "DateUploaded", WebControls.SortDirection.Descending)
            Me.BindGrid()
        End If

    End Sub

    Public Sub SetScreenPositioning(ByVal displayRowsLeftPosition As Integer, _
                                    ByVal rightCornerLeftPosition As Integer, _
                                    ByVal headerWidth As Integer, _
                                    ByVal gridWidth As Integer)

        'UserControlTableWidth=rightcornerleft + 9
        'MiddleColumnTableData = UserControlTableWidth - 18
        'DisplaySpanTableData = displayRowsLeftPosition - 9)
        'DisplayRowsTableData = MiddleColumnTableData - DisplaySpanTableData

        Dim usercontrolwidth As Integer = rightCornerLeftPosition + 9
        Dim middlecolumnwidth As Integer = usercontrolwidth - 18
        Dim displayspantabledata As Integer = displayRowsLeftPosition - 9

        Me.HeaderDiv.Style("width") = usercontrolwidth.ToString() & "px"
        Me.UserControlTable.Style("width") = usercontrolwidth.ToString() & "px"
        Me.GridTable.Style("width") = usercontrolwidth.ToString() & "px"
        Me.MiddleColumnTableData.Style("width") = middlecolumnwidth.ToString() & "px"
        Me.DisplaySpanTableData.Style("width") = (displayRowsLeftPosition - 9).ToString() & "px"
        Me.DisplayRowsTableData.Style("width") = (middlecolumnwidth - displayspantabledata).ToString() & "px"
        Me.AlertsGridView.Width = Unit.Pixel(usercontrolwidth)

    End Sub

    Protected Sub NumberOfRowsDropDownList_SelectedIndexChanged(ByVal sender As Object, _
                                                                ByVal e As System.EventArgs) _
                                                                Handles NumberOfRowsDropDownList.SelectedIndexChanged

        If NumberOfRowsDropDownList.SelectedValue = "-1" Then
            Me.AlertsGridView.AllowPaging = False
        Else
            AlertsGridView.AllowPaging = True
            AlertsGridView.PageSize = NumberOfRowsDropDownList.SelectedValue
            AlertsGridView.PageIndex = 0

        End If
        BindGrid()
    End Sub

    Public Sub BindGrid() Implements IDashBoard.BindGrid

        Me.AlertsGridView.DataSource = BatchUploadPortletDisplay.DisplayActivityList(Me.SortField, Me.SortDirection.Equals(SortDirection.Ascending))
        Me.AlertsGridView.DataBind()
        GridViewSettingController.SaveSetting(Me)
    End Sub

    Protected Sub AlertsGridView_PageIndexChanging(ByVal sender As Object, _
                                                   ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) _
                                                   Handles AlertsGridView.PageIndexChanging

        Me.PageNumber = e.NewPageIndex
        BindGrid()

    End Sub

    Public Sub LoadControl1(ByVal sender As Object, _
                        ByVal e As System.EventArgs) _
                        Implements IDashBoard.LoadControl

        Me.Page_Load(sender, e)

    End Sub

    Protected Sub AlertsGridView_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles AlertsGridView.Sorting
        If Me.SortDirection.Equals(SortDirection.Ascending) And _
          Me.SortField.Equals(e.SortExpression) Then
            Me.SortDirection = WebControls.SortDirection.Descending
        Else
            Me.SortDirection = WebControls.SortDirection.Ascending
        End If
        Me.SortField = e.SortExpression
        BindGrid()
    End Sub
End Class
